625C - K-special Tables - CodeForces Solution


constructive algorithms implementation *1300

Please click on ads to support us..

C++ Code:

//Not the Best :)
 
#include <bits/stdc++.h>
using namespace std;
 
//DataTypes
using str =  string;
using ll  = long long;
using ld  = long double;
using vl  = vector<ll>;
using vd  = vector<ld>;
using vs  = vector<str>;
using vpl = vector<pair<ll,ll>>;
#define umap unordered_map
#define uset unordered_set
 
//Shorts
#define pus     push_back
#define pub     pop_back
#define ff       first
#define ss       second
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
 
//Algorithms
#define sz(x)     ((ll)(x).size())
#define all(x)    x.begin(),x.end()
#define srt(x)    sort(all(x))
#define srtd(x)   sort(x.rbegin(),x.rend())
#define rev(x)    reverse(all(x));
#define Vmax(x)   *max_element(all(x))
#define Vmin(x)   *min_element(all(x))
#define Vsum(x)   accumulate(all(x),0ll)
#define lowB(v,x) *lower_bound(all(v),x) // >=x
#define upB(v,x)  upper_bound(all(v),x)-v.begin() // > x
#define ers(v,i)  v.erase(v.begin()+i) 
#define uniq(x)   x.erase(unique(all(x)),x.end())
#define NextP(x)  next_permutation(all(x))
#define PrevP(x)  prev_permutation(all(x))
#define cntB(x)   __builtin_popcountll(x)  
#define cntC(s,x) ll(count(all(s), x));
 
//loops
#define For(n)  for (ll i = 0; i < n; i++)
#define ForR(n) for (ll i = n-1; i >= 0; i--)
#define Forj(n) for (ll j = 0; j < n; j++)
#define For1(n) for (ll i = 1; i < n; i++)
 
//IO
#define nl      cout << "\n";
#define ya      cout << "YES\n";
#define na      cout << "NO\n";
#define inpt(v) For(sz(v)) cin >> v[i];
#define prt(v)  for(auto i:v) cout << i << " "; cout << "\n";
 
// ll binary(ll a, vector<ll>&v){
//     ll l=0, r=v.size()-1;
//     while(r-l>1){
//         ll mid=(l+r)/2;
//         if (a>v[mid]){
//             l=mid+1;
//         }
//         else r=mid;
//     }
//     if (v[r]==a) return r;
//     if(v[l]==a) return l;
//     else return -1;
// }
 
 
//Constants
const int M = 1e9+7; 
const int N = 2e5+5;
const ld pi = 3.141592653589793238;
const ll INF = 9e18;
 
ll n, a, b, c, k,z, m,d, x, y, q; str s;
 
//---------------------------------------------------------------------------------------------------------------------------------
//Let's Go :)

void solve()
{
    cin>>n>>k;
    x = 1;
    y = (k-1)*n +1;
    vector<vector<ll>> v(n,vector<ll>(n));
    For(n){
        Forj(n){
            if(j<(k-1)){
                v[i][j] = x;
                x++;
            }
            else{
                v[i][j]=y;
                y++;
            }
        }
        
    }
    c=0;
    For(n){
        c+= v[i][k-1];
    }
    cout<<c;nl
    For(n){
        Forj(n){
            cout<<v[i][j]<<" ";
        }
        nl
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t =  1;
    // cin>>t;
    while(t--) solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1719C - Fighting Tournament
1642A - Hard Way
285C - Building Permutation
1719E - Fibonacci Strings
1696C - Fishingprince Plays With Array
1085A - Right-Left Cipher
1508B - Almost Sorted
1690C - Restoring the Duration of Tasks
1055A - Metro
1036D - Vasya and Arrays
1139C - Edgy Trees
37A - Towers
353A - Domino
409H - A + B Strikes Back
1262A - Math Problem
158C - Cd and pwd commands
194A - Exams
1673B - A Perfectly Balanced String
1104B - Game with string
1169B - Pairs
1567D - Expression Evaluation Error
78A - Haiku
1287A - Angry Students
1428A - Box is Pull
234B - Reading
581B - Luxurious Houses
1481C - Fence Painting
935A - Fafa and his Company
22A - Second Order Statistics
1720B - Interesting Sum